﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Petzold.Media3D;
using System.Windows.Media.Media3D;
using System.Windows.Media;
using System.ComponentModel;

namespace PistonWheel
{
    public class Wheel:Cylinder,INotifyPropertyChanged,ICloneable
    {
        private double _angle;
        private double _angularVelocity;
        private double _time;

        public double AngularVelocity
        {
            get
            {
                return this._angularVelocity;
            }
            set
            {
                if (this._angularVelocity != value)
                {
                    this._angularVelocity = value;
                    this.NotifyPropertyChanged( "AngularVelocity" );
                }
            }
        }

        public double Radius
        {
            get
            {
                return this.Radius1;
            }
            set
            {
                this.Radius1 = value;
                this.Radius2 = value;
            }
        }

        public double Angle
        {
            get
            {
                return this._angle;
            }
            set
            {
                if (value != this._angle)
                {
                    this._angle = value;
                    this.NotifyPropertyChanged( "Angle" );
                }
            }
        }
        public double Mass { get; set; }

        public Point3D Middle
        {
            get
            {
                Point3D m = new Point3D();
                m.X = (this.Point1.X + this.Point1.X) / 2.0;
                m.Y = (this.Point1.Y + this.Point1.Y) / 2.0;
                m.Z = (this.Point1.Z + this.Point2.Z) / 2.0;
                return m;
            }
        }

        public double Time
        {
            get
            {
                return this._time;
            }
            set
            {
                if (this._time != value)
                {
                    this._time = value;
                    this.NotifyPropertyChanged( "Time" );
                }
            }
        }

        public Wheel(Brush backBrushMaterial, Brush frontBrushMaterial)
            : base()
        {
            DiffuseMaterial backMaterial = new DiffuseMaterial( backBrushMaterial );
            this.BackMaterial = backMaterial;
            DiffuseMaterial frontMaterial = new DiffuseMaterial( frontBrushMaterial );
            this.Material = frontMaterial;
            this.Angle = 0.0;
            this.Time = 0;
        }

        #region INotifyPropertyChanged Members

        public new event PropertyChangedEventHandler PropertyChanged;

        private void NotifyPropertyChanged(String info)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged( this, new PropertyChangedEventArgs( info ) );
            }
        }

        #endregion

        #region ICloneable Members

        public object Clone()
        {
            return this.MemberwiseClone();
        }

        #endregion
    }
}
